<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      button {
        background-color: aliceblue;
      }
    </style>
  </head>
  <body>
    <button>1</button>
    <button>2</button>
    <button>3</button>
    <button>4</button>
    <button>5</button>
    <script>
      var btn = document.getElementsByTagName("button");
      for (var i = 0; i < btn.length; i++) {
        btn[i].onclick = function () {
          for (var j = 0; j < btn.length; j++) {
            btn[j].style.backgroundColor = "";
          }
          this.style.backgroundColor = "red";
        };
      }
    </script>
  </body>
</html>
